package butines.core;

import java.awt.DisplayMode;
import java.util.HashMap;
import java.util.Map;

public class CompatiblesDisplay {

	private int width;
	private int height;
	private Map<Integer, DisplayMode> bitDepthMap = new HashMap<Integer, DisplayMode>();
	private Map<Integer, DisplayMode> refreshRateMap = new HashMap<Integer, DisplayMode>();
	private Map<String, DisplayMode> alias = new HashMap<String, DisplayMode>();

	public CompatiblesDisplay(DisplayMode dm) {
		this.width = dm.getWidth();
		this.height = dm.getHeight();
		addDisplayMode(dm);
	}

	public int getWidth() {
		return width;
	}

	public int getHeight() {
		return height;
	}

	public void addDisplayMode(DisplayMode dm) {
		int bitDepth = dm.getBitDepth();
		int refreshRate = dm.getRefreshRate();
		bitDepthMap.put(bitDepth, dm);
		refreshRateMap.put(refreshRate, dm);
		alias.put(bitDepth + "@" + refreshRate, dm);
	}

	public DisplayMode getDisplayMode(int bitDepth, int refreshRate) {
		return alias.get(bitDepth + "@" + refreshRate);
	}
	
	public DisplayMode getDisplayModeByBitDepth(int bitDepth) {
		return bitDepthMap.get(bitDepth);
	}
	
	public DisplayMode getDisplayModeByRefreshRate(int refreshRate) {
		return refreshRateMap.get(refreshRate);
	}

	public String getResolution() {
		return width + "x" + height;
	}

	public String toString() {
		return getResolution() + "x" + bitDepthMap.keySet() + "@" + refreshRateMap.keySet();
	}

}
